//
//  MyTableViewCell.m
//  chongwu
//
//  Created by 隼目 on 2021/9/23.
//

#import "MyTableViewCell.h"

@implementation MyTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(void)creatUserView{
    self.backgroundColor=[UIColor clearColor];
    
    
    self.contentView.userInteractionEnabled=YES;
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pushToPersonalInformation:)];
    [self.contentView addGestureRecognizer:tapGesture];
    
    UIImageView *userImage=[UIImageView new];
    [self.contentView addSubview:userImage];
    [userImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(59*_mainWidth);
        make.centerY.mas_equalTo(0);
        make.width.height.mas_equalTo(152*_mainWidth);
    }];
    userImage.layer.masksToBounds=YES;
    userImage.layer.cornerRadius=152/2*_mainWidth;
    [userImage sd_setImageWithURL:nil placeholderImage:[UIImage imageNamed:@"touxiang"]];

    
    UILabel *userNameLabel=[UILabel new];
    [self.contentView addSubview:userNameLabel];
    [userNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(userImage.mas_right).mas_equalTo(20*_mainWidth);
        make.top.mas_equalTo(userImage.mas_top).mas_equalTo(12*_mainHeight);
    }];
    
    NSString *typeStr=@"136****3326 ";
    NSMutableAttributedString *attri =  [[NSMutableAttributedString alloc] initWithString:typeStr];
    // 2.添加表情图片
    NSTextAttachment *attch = [[NSTextAttachment alloc] init];
    // 表情图片
    attch.image = [UIImage imageNamed:@"putonghuiyuan"];
        // 设置图片大小
    attch.bounds = CGRectMake(0, 0, 152*_mainWidth, 37*_mainHeight);
    // 创建带有图片的富文本
    NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];
    [attri insertAttributedString:string atIndex:typeStr.length];//插入某个位置
   
    userNameLabel.attributedText=attri;
    userNameLabel.textColor=rgba(254,255,254,1);
    userNameLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(40)];
    
    UIImageView *moerImage=[UIImageView new];
    [self.contentView addSubview:moerImage];
    [moerImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-67*_mainWidth);
        make.centerY.mas_equalTo(userNameLabel);
        make.width.mas_equalTo(_mainWidth*11);
        make.height.mas_equalTo(24*_mainHeight);
    }];
    moerImage.image=[UIImage imageNamed:@"chakangengduo"];
    
    UIView *allView=[UIView new];
    [self.contentView addSubview:allView];
    [allView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(userNameLabel);
        make.top.mas_equalTo(userImage.mas_top).mas_equalTo(84*_mainHeight);
        make.width.mas_equalTo(439*_mainWidth);
        make.height.mas_equalTo(14*_mainHeight);
    }];
    [allView layoutIfNeeded];
    allView.layer.masksToBounds=YES;
    allView.layer.cornerRadius=7*_mainHeight;
    allView.backgroundColor=rgba(233,233,233,1);
  
    CGFloat width=allView.frame.size.width;
    
    UIView *progressView=[UIView new];
    [allView addSubview:progressView];
    [progressView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.mas_equalTo(0);
        make.width.mas_equalTo(width*43/100);
    }];
    [progressView layoutIfNeeded];
    progressView.layer.masksToBounds=YES;
    progressView.layer.cornerRadius=7*_mainHeight;
    [progressView layoutIfNeeded];
//    progressView.backgroundColor=[UIColor redColor];
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.frame = progressView.bounds;
    //将CAGradientlayer对象添加在我们要设置背景色的视图的layer层
    [progressView.layer addSublayer:gradientLayer];
    //设置渐变区域的起始和终止位置（范围为0-1）
    gradientLayer.startPoint = CGPointMake(0, 1);
    gradientLayer.endPoint = CGPointMake(1, 1);
    gradientLayer.colors = @[(__bridge id)rgba(255,199,0,1).CGColor,
                             (__bridge id)rgba(255,251,172,1).CGColor];
    //设置颜色分割点（范围：0-1）
    gradientLayer.locations = @[@(0),@(1.0f)];
    
    UILabel *numLabel=[UILabel new];
    [self.contentView addSubview:numLabel];
    [numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(userNameLabel);
        make.top.mas_equalTo(userImage.mas_top).mas_equalTo(115*_mainHeight);
    }];
    numLabel.text=@"43/100";
    numLabel.textColor=rgba(254,255,254,1);
    numLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(26)];

    
}
-(void)creatCenterView{
    self.backgroundColor=[UIColor clearColor];
    UIView *backView=[UIView new];
    [self.contentView addSubview:backView];
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30*_mainHeight);
        make.right.mas_equalTo(-30*_mainWidth);
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(-10*_mainHeight);
    }];
    backView.backgroundColor=[UIColor whiteColor];
    backView.layer.cornerRadius=25*_mainWidth;
    backView.layer.shadowColor = rgba(74,31,0,0.1).CGColor;
    backView.layer.shadowOffset = CGSizeMake(0,0);
    backView.layer.shadowOpacity = 1;
    backView.layer.shadowRadius = 2;

    CGFloat width=(_mainW-40*_mainWidth)/3;
    
    NSArray *imageArr=[NSArray arrayWithObjects:@"积分",@"优惠券",@"权益卡", nil];
    NSArray *numArr=[NSArray arrayWithObjects:@"0",@"20",@"100", nil];
    for (int i=0; i<imageArr.count; i++) {
        UIView *btnView=[UIView new];
        [backView addSubview:btnView];
        [btnView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(width*i);
            make.width.mas_equalTo(width);
            make.top.bottom.mas_equalTo(0);
        }];
        btnView.tag=i;
        
        UIImageView *image=[UIImageView new];
        [btnView addSubview:image];
        [image mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(63*_mainHeight);
            make.centerX.mas_equalTo(0);
            make.width.height.mas_equalTo(80*_mainWidth);
        }];
        image.image=[UIImage imageNamed:imageArr[i]];
        
        UILabel *label=[UILabel new];
        [btnView addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(0);
            make.top.mas_equalTo(image.mas_bottom).mas_equalTo(15*_mainHeight);
        }];
        NSString *titleStr=[NSString stringWithFormat:@"%@：%@",imageArr[i],numArr[i]];
        NSMutableAttributedString *titleAttri =  [[NSMutableAttributedString alloc] initWithString:titleStr];
        NSRange priceRange = [titleStr rangeOfString:[NSString stringWithFormat:@"%@：",imageArr[i]]];//匹配得到的下标
        NSRange priceRange2 = [titleStr rangeOfString:[NSString stringWithFormat:@"%@",numArr[i]]];//匹配得到的下标
        [titleAttri addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"PingFang SC" size:autoScaleW(28)] range:priceRange];
        [titleAttri addAttribute:NSForegroundColorAttributeName value:rgba(47,47,47,1) range:priceRange];
        [titleAttri addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Helvetica-Bold" size:autoScaleW(34)] range:priceRange2];
        [titleAttri addAttribute:NSForegroundColorAttributeName value:rgba(255,104,4,1) range:priceRange2];
        label.attributedText=titleAttri;
        
    }
}
-(void)creatCellView{
    self.backgroundColor=[UIColor clearColor];
    UIView *backView=[UIView new];
    [self.contentView addSubview:backView];
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30*_mainHeight);
        make.right.mas_equalTo(-30*_mainWidth);
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(-10*_mainHeight);
    }];
    backView.backgroundColor=[UIColor whiteColor];
    backView.layer.cornerRadius=25*_mainWidth;
    backView.layer.shadowColor = rgba(74,31,0,0.1).CGColor;
    backView.layer.shadowOffset = CGSizeMake(0,0);
    backView.layer.shadowOpacity = 1;
    backView.layer.shadowRadius = 2;
    
    UILabel *titleLabel=[UILabel new];
    [backView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(51*_mainWidth);
        make.top.mas_equalTo(26*_mainHeight);
    }];
    titleLabel.text=@"便捷功能";
    titleLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(32)];
    titleLabel.textColor=rgba(44,46,52,1);
    [titleLabel layoutIfNeeded];

    CGFloat width=(_mainW-40*_mainWidth)/4;
    NSArray *imageArr=[NSArray arrayWithObjects:@"地址簿",@"我的宠物", nil];
    for (int i=0; i<imageArr.count; i++) {
        UIView *btnView=[UIView new];
        [backView addSubview:btnView];
        [btnView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(width*i);
            make.width.mas_equalTo(width);
            make.bottom.mas_equalTo(0);
            make.top.mas_equalTo(titleLabel.mas_bottom);
        }];
        btnView.tag=i+3;
        btnView.userInteractionEnabled=YES;
        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pushToMoreView:)];
        [btnView addGestureRecognizer:tapGesture];
        
        UIImageView *image=[UIImageView new];
        [btnView addSubview:image];
        [image mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(31*_mainHeight);
            make.centerX.mas_equalTo(0);
            make.width.height.mas_equalTo(50*_mainWidth);
        }];
        image.image=[UIImage imageNamed:imageArr[i]];
        
        UILabel *label=[UILabel new];
        [btnView addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(0);
            make.top.mas_equalTo(image.mas_bottom).mas_equalTo(21*_mainHeight);
        }];
        label.text=imageArr[i];
        label.textColor=rgba(47,47,47,1);
        label.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(24)];
    }
}
-(void)creatCellView2{
    self.backgroundColor=[UIColor clearColor];
    UIView *backView=[UIView new];
    [self.contentView addSubview:backView];
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30*_mainHeight);
        make.right.mas_equalTo(-30*_mainWidth);
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(-10*_mainHeight);
    }];
    backView.backgroundColor=[UIColor whiteColor];
    backView.layer.cornerRadius=25*_mainWidth;
    backView.layer.shadowColor = rgba(74,31,0,0.1).CGColor;
    backView.layer.shadowOffset = CGSizeMake(0,0);
    backView.layer.shadowOpacity = 1;
    backView.layer.shadowRadius = 2;
    
    UILabel *titleLabel=[UILabel new];
    [backView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(51*_mainWidth);
        make.top.mas_equalTo(26*_mainHeight);
    }];
    titleLabel.text=@"帮助";
    titleLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(32)];
    titleLabel.textColor=rgba(44,46,52,1);
    [titleLabel layoutIfNeeded];

    CGFloat width=(_mainW-40*_mainWidth)/4;
    NSArray *imageArr=[NSArray arrayWithObjects:@"客服中心",@"意见反馈",@"运费时效", nil];
    for (int i=0; i<imageArr.count; i++) {
        UIView *btnView=[UIView new];
        [backView addSubview:btnView];
        [btnView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(width*i);
            make.width.mas_equalTo(width);
            make.bottom.mas_equalTo(0);
            make.top.mas_equalTo(titleLabel.mas_bottom);
        }];
        btnView.tag=i;
        
        UIImageView *image=[UIImageView new];
        [btnView addSubview:image];
        [image mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(31*_mainHeight);
            make.centerX.mas_equalTo(0);
            make.width.height.mas_equalTo(50*_mainWidth);
        }];
        image.image=[UIImage imageNamed:imageArr[i]];
        
        UILabel *label=[UILabel new];
        [btnView addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(0);
            make.top.mas_equalTo(image.mas_bottom).mas_equalTo(21*_mainHeight);
        }];
        label.text=imageArr[i];
        label.textColor=rgba(47,47,47,1);
        label.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(24)];
    }
}
-(void)creatCellView3{
    self.backgroundColor=[UIColor clearColor];
    UIView *backView=[UIView new];
    [self.contentView addSubview:backView];
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30*_mainHeight);
        make.right.mas_equalTo(-30*_mainWidth);
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(-10*_mainHeight);
    }];
    backView.backgroundColor=[UIColor whiteColor];
    backView.layer.cornerRadius=25*_mainWidth;
    backView.layer.shadowColor = rgba(74,31,0,0.1).CGColor;
    backView.layer.shadowOffset = CGSizeMake(0,0);
    backView.layer.shadowOpacity = 1;
    backView.layer.shadowRadius = 2;
    
    UILabel *titleLabel=[UILabel new];
    [backView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(51*_mainWidth);
        make.top.mas_equalTo(26*_mainHeight);
    }];
    titleLabel.text=@"优惠活动";
    titleLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(32)];
    titleLabel.textColor=rgba(44,46,52,1);
    [titleLabel layoutIfNeeded];

    CGFloat width=(_mainW-40*_mainWidth)/4;
    NSArray *imageArr=[NSArray arrayWithObjects:@"邀请有奖",@"用户福利",@"秒杀商场", nil];
    for (int i=0; i<imageArr.count; i++) {
        UIView *btnView=[UIView new];
        [backView addSubview:btnView];
        [btnView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(width*i);
            make.width.mas_equalTo(width);
            make.bottom.mas_equalTo(0);
            make.top.mas_equalTo(titleLabel.mas_bottom);
        }];
        btnView.tag=i;
        
        UIImageView *image=[UIImageView new];
        [btnView addSubview:image];
        [image mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(31*_mainHeight);
            make.centerX.mas_equalTo(0);
            make.width.height.mas_equalTo(50*_mainWidth);
        }];
        image.image=[UIImage imageNamed:imageArr[i]];
        
        UILabel *label=[UILabel new];
        [btnView addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(0);
            make.top.mas_equalTo(image.mas_bottom).mas_equalTo(21*_mainHeight);
        }];
        label.text=imageArr[i];
        label.textColor=rgba(47,47,47,1);
        label.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(24)];
    }
}
-(void)pushToPersonalInformation:(UITapGestureRecognizer *)tap{
    if (self.delegate!=nil) {
        [self.delegate pushToPersonalInformation];
    }
}
-(void)pushToMoreView:(UITapGestureRecognizer *)tap{
    if (self.delegate!=nil) {
        [self.delegate pushToMoreView:tap.view.tag];
    }
}
@end
